<template>

<div id="ContributeMenu">
  <div id="homeBar">
    <mu-appbar title="贡献查询" style="background-color:#409EFF">
      <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'Home' }"/>
    </mu-appbar>
  </div>

  <mu-list>
    <mu-list-item title="" :to="{name: 'OnlineRecharge' }" v-if="this.isAdmin">
      <mu-avatar v-bind:src="this.$image.icon1" slot="leftAvatar"/>
      <div class="mu-item-title">今日充值<span style="color:red">&nbsp;{{this.todayRecharge}}</span></div>
      <mu-icon value="arrow_forward"  slot="right"/>
    </mu-list-item>
    <mu-list-item title="" :to="{name: 'OnlineRechargeHistory' }" v-if="this.isAdmin">
      <mu-avatar v-bind:src="this.$image.icon2" slot="leftAvatar"/>
      <div class="mu-item-title">累计充值<span style="color:red">&nbsp;{{this.totalRecharge}}</span></div>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="今日玩家贡献" :to="{name: 'UserContribute' }" v-if="!this.isAdmin">
      <mu-avatar v-bind:src="this.$image.icon3" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="历史玩家贡献" :to="{name: 'UserContributeHistory' }" v-if="!this.isAdmin">
      <mu-avatar v-bind:src="this.$image.icon4" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="" v-if="this.isAdmin">
      <mu-avatar v-bind:src="this.$image.icon1" slot="leftAvatar"/>
      <div class="mu-item-title">今日消耗金币<span style="color:red">&nbsp;{{this.todayAllNdot}}个</span></div>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="累计消耗金币" :to="{name: 'AllContributeHistory' }" v-if="this.isAdmin">
      <mu-avatar v-bind:src="this.$image.icon2" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="今日代理贡献" :to="{name: 'AgentNextContribute' }" v-if="isAgent || isCarrieroperator">
      <mu-avatar v-bind:src="this.$image.icon3" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="历史代理贡献" :to="{name: 'AgentNextContributeHistory' }" v-if="isAgent || isCarrieroperator">
      <mu-avatar v-bind:src="this.$image.icon4" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
  </mu-list>

</div>

</template>

<script>
  export default {
    data () {
      return {
        todayAllNdot: 0,
        condition: {
          startDay: this.$time.getDateBefore(new Date(), 0),
          endDay: this.$time.getDateBefore(new Date(), 0),
          account: sessionStorage.getItem('account')
        },
        isAdmin: false,
        isAgent: false,
        isCarrieroperator: false,
        todayRecharge: 0,
        totalRecharge: 0
      }
    },
    methods: {
      getAllContribute () {
        let that = this
        this.$axios({
          method: 'get',
          url: '/api/AgentService.getAllContribute',
          params: this.condition
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            that.todayAllNdot = resp.data.todayAllNdot
          }
        })
      },
      init () {
        if (this.isAdmin) {
          this.getAllContribute()
          this.getTotalRecharge()
        }
      },
      getTotalRecharge () {
        let that = this
        this.$axios({
          method: 'get',
          url: '/api/CarrieroperatorService.getTotalRecharge',
          params: this.condition
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            that.totalRecharge = resp.data.totalRecharge
            that.todayRecharge = resp.data.todayRecharge
          }
        })
      }
    },
    mounted () {
      if (sessionStorage.getItem('role') === 'admin') {
        this.isAdmin = true
      }
      if (sessionStorage.getItem('role') === 'agent') {
        this.isAgent = true
      }
      if (sessionStorage.getItem('role') === 'carrieroperator') {
        this.isCarrieroperator = true
      }
      this.init()
    }
  }
</script>
